import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;


public class game {
	//variables
	ArrayList<player> players;
	deck thedeck;
	ArrayList<card> dealerHand;
	private int dealerscore;
	
	//constructor
	public game(ArrayList<player> players, deck thedeck){
		this.players= new ArrayList<player>();
		this.players.addAll(players);
		this.thedeck=thedeck;
		dealerHand= new ArrayList<card>();
		this.dealerscore=0;
		thedeck.shuffle();
		
		System.out.println("The deck has been shuffled");
		//System.out.println(thedeck.toString());
		
	}
	
	//methods
	
	public void playGame(){
		boolean gamewon=false;
		dealInitialHand();
		//loop that handles all player turns
		System.out.println("Playing game with players "+players.size());
		while(gamewon=false){
			
			for(int i=0; i<players.size(); i++)
			{
				playerturn(i);
			
			}
			dealerturn();
		}
	}

	
	//deal initial hand 
	private void dealInitialHand(){
		for(int i=0; i<players.size(); i++){
			players.get(i).hitCard(thedeck.draw());
			players.get(i).hitCard(thedeck.draw());
		}
		
		dealerHitCard(thedeck.draw());
		dealerHitCard(thedeck.draw());
		//dealerHand.add(thedeck.draw());
		//dealerHand.add(thedeck.draw());
	}
	//player turn
	public void playerturn(int playernum){
		
		int hitOrStay=2;
		System.out.println( players.get(playernum).getName()+"'s score:"+players.get(playernum).getScore());
		while(hitOrStay>0){
			System.out.println("1. Hit or 0. stay?");
			Scanner sc=new Scanner(System.in);
			hitOrStay = sc.nextInt();
		
			if(hitOrStay==1){
			
				players.get(playernum).hitCard(thedeck.draw());
				hitOrStay=2;
				System.out.println(players.get(playernum).getName()+"'s score is now "+players.get(playernum).getScore());
			}
			else if(hitOrStay==0){
				
			}
			if(players.get(playernum).getScore()>21){
			
				System.out.println(players.get(playernum).getName()+"lost!!");
				players.remove(playernum);
				//players.get(playernum).playerlost = true;
			
			}
		}
	}
	//dealer hit card
	public void dealerHitCard(card c){
		
		dealerHand.add(c);
		dealerscore+=c.getValue();
		
	}
	
	
	
	
	//dealer's turn
	public void dealerturn(){
		
		System.out.println("Dealer's Turn");
		if(dealerscore>=16){
			
			
			
		}else{
			dealerHitCard(thedeck.draw());
		}
		if
	}
	
	
	
	
}
